package com.fileio;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

public class FileIOActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	TextView textView1 = (TextView)findViewById(R.id.textView1);
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
		String FILENAME = "derp.txt";
		String string = "this is the contents of the file\nthis is line 2\nthis is line 3";

		FileOutputStream fos;
		try {
			fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
			fos.write(string.getBytes());
			fos.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        try{
        FileInputStream in = openFileInput("derp.txt");
        	if(in != null){
        		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        		while((string = reader.readLine()) != null){
        			textView1.setText(string);
        		}
        			in.close();
        	}
        
    
    
        } catch (IOException ioe) {
			System.out.println("FIX YOUR CODE BRO");
		}
    
    
    }

	private OutputStream openFileOutput(String string) {
		return null;
	}
    
    
}